package com.allwees.bs.c.module.payment.entity;

import com.allwees.bs.c.module.base.entity.JpaBaseEntity;
import com.allwees.bs.c.module.order.entity.OrderEntity;
import com.allwees.support.payment.EPayMethod;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;

import javax.persistence.Entity;
import javax.persistence.Table;
import java.math.BigDecimal;
import java.util.Date;

/**
 *   支付记录
 */
@Data
@EqualsAndHashCode(callSuper = true)
@AllArgsConstructor
@NoArgsConstructor
@Entity()
@Table(name = "pay_payment_log")
public class PaymentLogEntity extends JpaBaseEntity {
    private String no;

    //支付方式，paypal,credit
    private String type;

    //订单ID
    private String orderUuid;

    //订单总价
    private BigDecimal amt;

    //币种
    private String currency;

    //第三方的支付token
    private String paymentToken;

    //第三方支付的交易流水号
    private String paymentNumber;

    //支付者账号邮箱
    private String payerEmail;

    //支付者ID
    private String payerId;

    //支付方式，在paypal下级的支付方式，信用卡，余额等
    private String paymentType;

    //退款状态
    private Integer refundStatus;

    //退款金额
    private BigDecimal refundAmt;

    //退款时间
    private Date refundTime;

    //支付过期时间
    private Date paymentExpiresAt;

    public PaymentLogEntity build(OrderEntity order, int status, EPayMethod payMethod) {
        this.setType(payMethod.name());
        this.setOrderUuid(order.getUuid());
        this.setStatus(status);
        this.setAmt(order.getAmt());
        this.setCurrency(order.getCurrency());
        return this;
    }
}
